<script type="text/javascript">


function saveRoomConfigInfo() {
	var rows = $('#roomConfigSelectDeviceLinkList').datagrid('getRows');
	var roomConfigInfo = [{
		id:$('#roomConfigId').val(),
		roomType:$('#roomConfigRoomType').combobox('getText'),
		configInfo:$('#configInfo').val(),
		deviceLinks:rows
	}];
	printLog(roomConfigInfo);
	$.post("roomConfig.do?saveRoomConfigInfos", {data:JSON.stringify(roomConfigInfo)}, function(result) {
          if(result.success){
	       	  showMsg('保存成功.');
	       	  reloadRoomConfig();
          }else {
       	  	  showMsg('保存失败.');
          }
  	}, "JSON");
	
}

var i = 0, getDeviceLinkValueRow = function() {
	return {
            "id": ++i, 
            "lid": "1", 
            "ltype": "ac",
            "addr":"1",
            "channel":"1"
	};
};
function addDeviceLinkInEdit() {
	deviceLinkAddList.datagrid("appendRow", getDeviceLinkValueRow());
}

function deleteDeviceLinkInEdit() {
	var rows = deviceLinkAddList.datagrid('getChecked');
// 	printLog(rows);
    if (rows&&rows.length>0){
//     	printLog(rows.length);
//     	var copyRows = rows.slice(0);
//     	printLog(copyRows);
        $.messager.confirm('询问','你确认要删除记录吗?',function(r){
            if (r){
            	for (var i = rows.length - 1; i >= 0; i--) {
            		printLog(rows[i]);
            		var index = deviceLinkAddList.datagrid('getRowIndex', rows[i]);
            		deviceLinkAddList.datagrid('deleteRow', index);
            	}
            }
        });
    }else {
    	showMsg("请选择操作记录.");
    }
}
</script>
<div class="easyui-layout" data-options="fit:true">
    <div data-options="region: 'north', border:false" style="height:35px" >
		<table cellpadding="5">
			<input id="roomConfigId" name="id" type="hidden" value="${(roomConfigItem.id)!}" />
			<tr>
				<td>房间类型:</td>
				<td>
					<@eu.comboBox id="roomConfigRoomType" url="common.do?loadComboBox&key=ROOM_TYPE&text=${(roomConfigItem.roomType)!}" name="roomType" required="true" validType="remote['roomConfig.do?checkConfigIsExit&id=${(roomConfigItem.id)!}','roomType']" invalidMessage="请勿重复配置相同酒店类型"/>
				</td>
			</tr>
<!-- 			<tr> -->
<!-- 				<td>配置信息:</td> -->
<!-- 				<td> -->
<!-- 					<textarea id="configInfo" style="height: 140px;width:650px" rows="6"  name="configInfo" class="easyui-validatebox" data-options="required: true"  readonly="readonly" missingMessage="请在下面选择房间配置的元件信息" >${(roomConfigItem.configInfo)!}</textarea> -->
<!-- 				</td> -->
<!-- 			</tr> -->
		</table>
	</div>
	<div data-options="region:'center',border:false,fit:true,title:'配置元件设备'">
		<@eu.datagrid id="deviceLinkAddList"  idField="id" toolbar="#deviceLinkAddListToolbar" autoEditing="true" singleEditing="true" extEditing="true"
					 url="roomConfig.do?loadRoomConfigSelectDeviceLinks" rownumbers="true" pagination="false"
					 item="com.xdtech.hotel.vo.DeviceLinkItem"/>
			 
		<div id="deviceLinkAddListToolbar">
			<@eu.linkbutton showName="新增" shiro="hotel:deviceLink:add" iconCls="icon-add" onclick="addDeviceLinkInEdit()"/>
			<@eu.linkbutton showName="删除" shiro="hotel:deviceLink:delete" iconCls="icon-remove" onclick="deleteDeviceLinkInEdit()"/>
		</div>
	</div>
</div>
